package com.tian.scroll.view_move.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;

import com.tian.scroll.R;
import com.tian.scroll.databinding.FragmentMoveViewLayoutParamBinding;

public class LayoutParamsViewFragment extends Fragment {

    private FragmentMoveViewLayoutParamBinding b;

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        b = DataBindingUtil.inflate(inflater, R.layout.fragment_move_view_layout_param, container, false);
        b.mbtLayoutView.setOnClickListener(v -> {
            RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) b.mbtLayoutView.getLayoutParams();
            layoutParams.leftMargin += 20;
            layoutParams.topMargin += 20;
            b.mbtLayoutView.setLayoutParams(layoutParams);

            //或者
            //b.mbtLayoutView.offsetLeftAndRight(20);
            //b.mbtLayoutView.offsetTopAndBottom(20);
        });
        return b.getRoot();
    }
}